﻿// This code is released under the BSD license.
namespace PugLib.UnitTest
{
    using System;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using TestCollateral;

    [TestClass]
    public class NotifyChangedTest
    {
        [TestMethod]
        public void NotifyObjectChangedTest()
        {
            NotifyChanged<Computer> notifier = NotifyChanged.Create<Computer>(notifier_ItemChanged);
            notifier.State = Computer.CreateRandom();

            notifier = new NotifyChanged<Computer>();
            notifier.StateChanged += notifier_ItemChanged;
            notifier.State = Computer.CreateRandom();
        }

        private static void notifier_ItemChanged(object sender, StateChangedEventArgs<Computer> e)
        {
            Assert.IsNotNull(sender);
            Assert.IsNotNull(e.State);
            NotifyChanged<Computer> senderCast = sender as NotifyChanged<Computer>;
            if (senderCast != null)
            {
                Assert.AreEqual(senderCast.State, e.State);
            }
            Console.WriteLine("notifier_ItemChanged: " + e.State);
        }
    }
}